package org.example.spring.ioc.dao;

import lombok.ToString;
import org.example.spring.ioc.bean.Dog;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Repository;

@Repository
@ToString
public class Dao implements EnvironmentAware {
    /*
    * 构造器注入
    * Spring推荐：即使脱离Spring环境，没有无参构造器，会报错提示你把相关依赖注入
    */
    //Spring自动去容器中找到构造器所有参数的组件值
    Dog dog;
    public Dao(Dog dog)
    {
        System.out.println("Dao 有参构造器注入");
        this.dog = dog;
    }

    //感知接口
    private Environment environment;

    @Override
    public  void setEnvironment(Environment environment){
        this.environment = environment;
    }

    public String getEnvironment(){
        return environment.getProperty("OS");
    }
}
